package com.ruoyi.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.order.domain.OrderForm;
import com.ruoyi.order.service.IOrderFormService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2023-02-09
 */
@RestController
@RequestMapping("/form")
public class OrderFormController extends BaseController
{
    @Autowired
    private IOrderFormService orderFormService;

    /**
     * 查询订单列表
     */
    @RequiresPermissions("order:form:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderForm orderForm)
    {
        startPage();
        List<OrderForm> list = orderFormService.selectOrderFormList(orderForm);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @RequiresPermissions("order:form:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderForm orderForm)
    {
        List<OrderForm> list = orderFormService.selectOrderFormList(orderForm);
        ExcelUtil<OrderForm> util = new ExcelUtil<OrderForm>(OrderForm.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("order:form:query")
    @GetMapping(value = "query/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(orderFormService.selectOrderFormByOrderId(orderId));
    }

    /**
     * 新增订单
     */
    @RequiresPermissions("order:form:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OrderForm orderForm)
    {
        return toAjax(orderFormService.insertOrderForm(orderForm));
    }

    /**
     * 修改订单
     */
    @RequiresPermissions("order:form:edit")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody OrderForm orderForm)
    {
        return toAjax(orderFormService.updateOrderForm(orderForm));
    }

    @RequiresPermissions("order:form:pay")
    @PutMapping("/pay")
    public AjaxResult pay(@RequestBody OrderForm orderForm)
    {
        orderForm.setOrderState(1L);
        return toAjax(orderFormService.updateOrderForm(orderForm));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("order:form:remove")
	@DeleteMapping("remove/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(orderFormService.deleteOrderFormByOrderIds(orderIds));
    }
}
